package com.example.aircraftwar.application;

import android.view.MotionEvent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.aircraftwar.aircraft.HeroAircraft;
import com.example.aircraftwar.application.game.Game;

/**
 * 英雄机控制类
 * 监听触摸，控制英雄机的移动
 *
 * @author hitsz
 */
public class HeroController extends AppCompatActivity {
    private Game game;
    private HeroAircraft heroAircraft;

    public HeroController(Game game, HeroAircraft heroAircraft){
        super();
        this.game = game;
        this.heroAircraft = heroAircraft;

        game.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                float x = motionEvent.getX();
                float y = motionEvent.getY();
                if ( x<0 || x>MainActivity.WINDOW_WIDTH || y<0 || y>MainActivity.WINDOW_HEIGHT){
                    // 防止超出边界
                    return false;
                }
                heroAircraft.setLocation(x, y);
                return true;
            }
        });
    }


}
